<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form action="" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
					    <div class="search_elm" style="margin-left: 0px">
							<label class="label_search">合作机构号:</label>
							<div class="search_input">
								<input id="search_cooporgNo" type="text" name="cooporgNo"
									placeholder="请输入合作机构编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="search_merNo" type="text" name="merNo"
									placeholder="请输入合作机构商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">终端号:</label>
							<div class="search_input">
								<input id="search_terNo" type="text" name="terNo"
									placeholder="请输入合作机构终端号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="search_merName" type="text" name="merName"
									placeholder="请输入合作机构商户名称">
							</div>
						</div>
						
						<div class="search_elm">
							<label class="label_search" >商户状态:</label>
							<div class="search_input">
							    <select 
									 rel="obj.MERSTATUS"
						 			 location="local" 
									 name="merStatus" 
						 			id="search_merStatus" 
						 			data-placeholder="请选择状态" style="width: 120px;vertical-align:middle;">
									<option value='' >--请选择--</option>
							 </select>
							
							</div>
						</div>
						<div class="search_elm">
							<label class="label_search" >费率类型:</label>
							<div class="search_input">
							    <select 
									 rel="obj.RATETYPE"
						 			 location="local" 
									 name="rateType" 
						 			id="search_rateType" 
						 			data-placeholder="请选择状态" style="width: 120px;vertical-align:middle;">
									<option value='' >--请选择--</option>
							 </select>
							
							</div>
						</div>		
						<div class="search_elm">
							<button class="btn btn-small btn_search" type="submit" title="搜索" >
								搜索
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
	<div class="row">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			
			<div style="margin-top: 10px">
				<span id="auth_btn">
					 <a class="btn btn-small btn-default" onclick="coopOrgMerSelectInf();">详情</a>
					<a  class="btn btn-small btn-add" onclick="coopOrgMerAdd();">新增</a> 
					<a  class="btn btn-small btn-update" onclick="coopOrgMeredit();"> 修改 </a> 
					<a  class="btn btn-small btn-delete" onclick="coopOrgMerdelete();">  删除</a>
					<a class="btn btn-small btn-default" onclick="OrgMerSignIn();">签到</a>
					<a class="btn btn-small btn-default" onclick="OrgMerSettlement();">批结算</a>
				<!-- <a class="btn btn-small btn-default"
					onclick="statusUpdate0();">启用
				</a>
				<a class="btn btn-small btn-default"
					onclick="statusUpdate1();">禁用
				</a> -->
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>
			<!-- PAGE CONTENT ENDS -->
		</div>
		<!-- /.col -->
	</div>
	<!-- /.row -->

	<!-- page specific plugin scripts -->
	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',
								$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'
								|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',
										parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({

				url : "mpcoop/cooporgmer/coopOrgMerManage/query.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ 
				              								'合作机构编号',
								'商户编号',
								'终端编号',
								'商户名称',
								'商户密钥(快捷通道/终端主密钥)',
								'商户状态',
								
								'上次签到时间',
								'费率类型',
								'费率封顶'
				           ],
				colModel : [ 
							     {name : 'cooporgNo',        index : 'cooporgNo',        width : '130px',sortable:false }, 
							     {name : 'merNo',        index : 'merNo',        width : '130px' ,sortable:false}, 
							     {name : 'terNo',        index : 'terNo',        width : '100px',sortable:false }, 
							     {name : 'merName',        index : 'merName',        width : '140px' ,sortable:false}, 
							     {name : 'merKey',        index : 'merKey',        width : '280px',sortable:false },   
							     {name : 'merStatus',        index : 'merStatus',        width : '100px',sortable:false ,ditcKey:'MERSTATUS', formatter : gridFormatByDict},  
							      
							     {name : 'signTime',        index : 'signTime',        width : '150px' ,sortable:false,formatter : gridFormatByDate}, 
							     {name : 'rateType',        index : 'rateType',        width : '100px',sortable:false, formatter : rateTypeFormat}, 
							     {name : 'rateTypeTop',  index : 'rateTypeTop',   hidden : true,sortable:false}, 
							      
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,
				shrinkToFit : false,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//
				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
			
			
			function rateTypeFormat(cellvalue, options, rowObject){
				var ratetype=DICT.get("RATETYPE")[cellvalue]||'';
				if(rowObject.rateTypeTop!=null&&rowObject.rateTypeTop!="0"){
					ratetype+=" - "+rowObject.rateTypeTop+" 封顶";
				}
				return ratetype;
			}
			
		});

		
		//单条合作机构商户终端信息
		function coopOrgMerSelectInf() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			var cooporgno = "";
			var merno = "";
			var terno = "";
			for (var i = 0; i < rows.length; i++) {
				cooporgno += $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ ",";
				merno += $('#grid-table').jqGrid('getRowData',rows[i]).merNo+ ",";
				terno += $('#grid-table').jqGrid('getRowData',rows[i]).terNo+ ",";
			}
			openDialog({
				dialogId : 'dlg-coopOrgTerselectinf',
				title : '查看合作机构商户终端信息',
				pageUrl : 'mpcoop/cooporgmer/coopOrgMerManage/selectinfView.do',
				dataUrl : 'mpcoop/cooporgmer/coopOrgMerManage/queryCoopOrgMerById.do?cooporgNo='+cooporgno+'&merNo='+merno+'&terNo='+terno,
				width : '70%',
			    height:'85%',
			    dataParam : {
					id : rows[0],
					editUserId:UID.id,
					editUserName:UID.userName
				},
				dataName : 'obj' //表单数据存储对象名称
			});
		}
		
		
		//新增
		//添加合作机构商户终端信息
		function coopOrgMerAdd() {
			openDialog({
				dialogId : 'dlg-coopOrgMerAdd',
				title : '新增合作机构商户终端',
				pageUrl : 'mpcoop/cooporgmer/coopOrgMerManage/addView.do',
				width : '60%',
			    height:'80%',
			    dataParam : {
					editUserId:UID.id,
					editUserName:UID.userName
				},
				dataName : 'obj' //表单数据存储对象名称
			});
		}
		//编辑合作机构商户终端
		function coopOrgMeredit() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "error");
				return;
			}
			if (rows.length > 1) {
				msg.alert("警告", "不能同时选择多项数据！", "warn");
				return;
			}
			var cooporgno = "";
			var merno = "";
			var terno = "";
			for (var i = 0; i < rows.length; i++) {
				cooporgno += $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ ",";
				merno += $('#grid-table').jqGrid('getRowData',rows[i]).merNo+ ",";
				terno += $('#grid-table').jqGrid('getRowData',rows[i]).terNo+ ",";
			}
			
			openDialog({
				dialogId : 'dlg-coopOrgMeredit',
				title : '编辑用户',
				pageUrl : 'mpcoop/cooporgmer/coopOrgMerManage/editView.do',
				dataUrl : 'mpcoop/cooporgmer/coopOrgMerManage/queryCoopOrgMerById.do?cooporgNo='+cooporgno+'&merNo='+merno+'&terNo='+terno,
				width :'70%',
				height:'85%',
				dataParam : {
					id : rows[0],
					editUserId:UID.id,
					editUserName:UID.userName,
					cooporgno : cooporgno
				},
				dataName : 'obj' //表单数据存储对象名称

			});
		}
		//删除
		function coopOrgMerdelete() {
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}

			//
			var cooporgno = "";
			var merno = "";
			var terno = "";
			for (var i = 0; i < rows.length; i++) {
				cooporgno += $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ ",";
				merno += $('#grid-table').jqGrid('getRowData',rows[i]).merNo+ ",";
				terno += $('#grid-table').jqGrid('getRowData',rows[i]).terNo+ ",";
			}
			cooporgno = cooporgno.substring(0, cooporgno.lastIndexOf(","));
			merno = merno.substring(0, merno.lastIndexOf(","));
			terno = terno.substring(0, terno.lastIndexOf(","));
			msg.confirm({title:'确认',position:'center',msg:'您确定要删除选中的数据吗？',call:function(ok){
				if(ok){
					$.ajax({
						type : "post",
						url : "mpcoop/cooporgmer/coopOrgMerManage/delete.do?cooporgNo=" + cooporgno+"&merNo="+merno+"&terNo="+terno,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});

				}
			}});
			
			}
		function OrgMerSignIn(){
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}
			var cooporgno = "";
			var merno = "";
			var terno = "";
			for (var i = 0; i < rows.length; i++) {
				cooporgno += $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ ",";
				merno += $('#grid-table').jqGrid('getRowData',rows[i]).merNo+ ",";
				terno += $('#grid-table').jqGrid('getRowData',rows[i]).terNo+ ",";
			}
			cooporgno = cooporgno.substring(0, cooporgno.lastIndexOf(","));
			merno = merno.substring(0, merno.lastIndexOf(","));
			terno = terno.substring(0, terno.lastIndexOf(","));
			/* openDialog({
				dialogId : 'dlg-coopOrgSignIn',
				title : '签到合作机构商户终端',
				pageUrl : 'mpcoop/cooporgmer/coopOrgMerManage/editView.do',
				dataUrl : 'mpcoop/cooporgmer/coopOrgMerManage/queryCoopOrgMerById.do?cooporgNo='+cooporgno+'&merNo='+merno+'&terNo='+terno,
				width :'70%',
				height:'85%',
				dataParam : {
					id : rows[0],
					editUserId:UID.userName
				},
				dataName : 'obj' //表单数据存储对象名称

			}); */
			msg.confirm({title:'确认',position:'center',msg:'您确定要签到(重新签到)所选合作机构商户终端？',call:function(ok){
				if(ok){
					//根据合作机构编号查找路由信息
					/* $.ajax({
						type : "post",
						url:"mpcoop/cooporgroute/coopOrgRouteManage/queryCoopOrgRouteMsg.do?cooporgNo=" + cooporgno+"&txncd=0800",
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					}); */
					$.ajax({
						type : "post",
						url : "mpcoop/cooporgmer/coopOrgMerManage/orgmersgin.do?cooporgNo=" + cooporgno+"&merNo="+merno+"&terNo="+terno,
						//url:"mpcoop/bankRtr/bankRtrSign.do?cooporgNo=" + cooporgno+"&merNo="+merno+"&terNo="+terno,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});
				}
			}}); 
		}
		
		/**
		*批结算
		*/
		function OrgMerSettlement(){
			var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
			if (rows.length == 0) {
				msg.alert("警告", "当前没有选择数据项！", "warn");
				return;
			}
			var cooporgno = "";
			var merno = "";
			var terno = "";
			for (var i = 0; i < rows.length; i++) {
				cooporgno += $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ ",";
				merno += $('#grid-table').jqGrid('getRowData',rows[i]).merNo+ ",";
				terno += $('#grid-table').jqGrid('getRowData',rows[i]).terNo+ ",";
			}
			cooporgno = cooporgno.substring(0, cooporgno.lastIndexOf(","));
			merno = merno.substring(0, merno.lastIndexOf(","));
			terno = terno.substring(0, terno.lastIndexOf(","));
			msg.confirm({title:'批结算确认',position:'center',msg:'您确定要对选中的商户发起批结算操作吗？',call:function(ok){
				if(ok){
					//发起批结算
					$.ajax({
						type : "post",
						url : "mpcoop/cooporgmer/coopOrgMerManage/orgmerSettlement.do",
						//url:"mpcoop/bankRtr/bankRtrSign.do?cooporgNo=" + cooporgno+"&merNo="+merno+"&terNo="+terno,
						data : {
							"cooporgNo" : cooporgno,
							"merNo" : merno,
							"terNo" : terno
						},
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："
									+ textStatus, 'error');
						}
					});
				}
			}}); 
		}
	</script>